/**
 * @param {string} s
 * @return {boolean}
 * @description 首先提出字母和数字，再转为数组
 * @description 方法1.reverse，
 * @description 方法2.双指针判断，
 */
let a = ' ';
let b = 'A man, a plan, a canal: Panama';
let c = 'sb_hoa'
let d = ''
let e = 'ab_a'
let f = '-'
let g = '_'


 var isPalindrome = function(s) {
    const reg = /\w+/g;     // \w匹配字母或数字及下划线，/g全局匹配
    let res = s.match(reg)  //match 返回 的是字符串数组
    // console.log(s,res);
    //Cannot read properties of null (reading 'join') 要先判断是否为空
    if (!res) return true

    //join 将数组拼接成字符串
    let newS = res.join('').replace(/_/g,'').toLowerCase();

    let slength = newS.length;
    var i=0;
    var j=slength-1;
    for(i;i<j;i++){
        if(newS[i] !== newS[j])
            return false;
        --j;
    }
    return true
};

console.log(isPalindrome(a)); 
console.log(isPalindrome(b)); 
console.log(isPalindrome(c)); 
console.log(isPalindrome(d)); 
console.log(isPalindrome(e));
console.log(isPalindrome(f)); 
console.log(isPalindrome(g));